class Solution
{
public:
    vector<int> searchRange(vector<int> &nums, int target)
    {
        if (nums.size() == 0)
        {
            return {-1, -1};
        }
        if (nums.size() == 1)
        {
            if (nums[0] == target)
            {
                return {0, 0};
            }
            else
            {
                return {-1, -1};
            }
        }
        int leftBound = -1;
        int rightBound = -1;

        int left = 0;
        int right = nums.size() - 1;
        while (left < right)
        {
            int mid = (left + right) / 2;
            if (nums[mid] == target && nums[mid + 1] > target)
            {
                rightBound = mid;
                break;
            }
            else if (nums[mid] > target)
            {
                right = mid;
            }
            else
            {
                left = mid + 1;
            }
        }
        if (nums[nums.size() - 1] == target)
        {
            rightBound = nums.size() - 1;
        }

        left = 0;
        right = nums.size() - 1;
        while (left < right)
        {
            int mid = (left + right + 1) / 2;
            if (nums[mid] == target && nums[mid - 1] < target)
            {
                leftBound = mid;
                break;
            }
            else if (nums[mid] < target)
            {
                left = mid;
            }
            else
            {
                right = mid - 1;
            }
        }
        if (nums[0] == target)
        {
            leftBound = 0;
        }

        return {leftBound, rightBound};
    }
};